home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMIBEST2.ADF
/
Best of AMICUS 2
/
C
/
Gadgets
/
str.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-07-22
|
13KB
|
313 lines
/****************************************************************/
/* Example "C" program showing use of string gadgets. */
/* This was compiled using Lattice "C", AmigaDos V1.2 */
/* The code depends on V1.2 functions to operate correctly. */
/* It is intended to be run from CLI. */
/* */
/* Copyright (C) 1987 H. Maybeck Tolly, TollySoft */
/* This program is in the public domain and may be distributed */
/* free of charge. */
/* */
/****************************************************************/
#include "exec/types.h"
#include "exec/exec.h"
#include "intuition/intuition.h"
#include "graphics/gfxbase.h"
UWORD StrVectors[] = {0, 0, 97, 0, 97, 9, 0, 9, 0,0};
struct Border StrBorder = {
-1, -1, /* initial offsets, gadget relative */
3, 2, JAM1, /* pens (fore, back) and drawmode */
5, /* number of vectors */
StrVectors, /* pointer to the actual array of vectors */
NULL /* no next border */
};
char UndoBuffer[5][41];
char item_string[10][41] = {{"0 String item\0 "},
{"1 String item\0 "},
{"2 String item\0 "},
{"3 String item\0 "},
{"4 String item\0 "},
{"5 String item\0 "},
{"6 String item\0 "},
{"7 String item\0 "},
{"8 String item\0 "},
{"9 String item\0 "}};
struct StringInfo StringInfo[5]= {
{
item_string[0], /* pointer to I/O buffer */
UndoBuffer[0], /* pointer to undo buffer */
0, /* buffer position */
41, /* max number of chars, including NULL */
0, 0, /* first char in display, undo positions */
0, /* number of chars (currently) in the buffer */
0, 0, 0, /* position variables calculated by Intuition */
NULL, /* no pointer to RastPort */
0, /* not a LongInt string gadget */
NULL /* no pointer to alternate keymap */
},
{item_string[1],UndoBuffer[1],0,41,0,0,0,0,0,0,NULL,0,NULL},
{item_string[2],UndoBuffer[2],0,41,0,0,0,0,0,0,NULL,0,NULL},
{item_string[3],UndoBuffer[3],0,41,0,0,0,0,0,0,NULL,0,NULL},
{item_string[4],UndoBuffer[4],0,41,0,0,0,0,0,0,NULL,0,NULL}
};
struct Gadget StrGadget[5] = {
{
NULL, /* pointer to Next Gadget */
6,20, -509, 7, /* (Left Top Width Height) Hit Box */
GADGHCOMP | GRELWIDTH, /* Flags */
GADGIMMEDIATE | RELVERIFY, /* Activation flags */
STRGADGET, /* Type */
(APTR)&StrBorder, /* pointer to Border Image */
NULL, /* no pointer to SelectRender */
NULL, /* pointer to GadgetText */
0, /* no MutualExclude */
(APTR)&StringInfo[0], /* pointer to SpecialInfo */
0, /* no ID */
NULL /* no pointer to special data */
},
{&StrGadget[0],6,40,96,7,GADGHCOMP ,GADGIMMEDIATE | RELVERIFY,
STRGADGET,(APTR)&StrBorder,NULL,NULL,0,(APTR)&StringInfo[1],0,NULL},
{&StrGadget[1],6,60,96,7,GADGHCOMP ,GADGIMMEDIATE | RELVERIFY,
STRGADGET,(APTR)&StrBorder,NULL,NULL,0,(APTR)&StringInfo[2],0,NULL},
{&StrGadget[2],6,80,96,7,GADGHCOMP ,GADGIMMEDIATE | RELVERIFY,
STRGADGET,(APTR)&StrBorder,NULL,NULL,0,(APTR)&StringInfo[3],0,NULL},
{&StrGadget[3],6,100,96,7,GADGHCOMP | GADGDISABLED ,
GADGIMMEDIATE | RELVERIFY, STRGADGET,(APTR)&StrBorder,NULL,
NULL,0,(APTR)&StringInfo[4],0,NULL}
};
struct IntuitionBase *IntuitionBase = 0;
struct GfxBase *GfxBase = 0;
struct Window *ControlWindow = NULL;
struct IntuiMessage *MyIntuiMessage;
struct NewWindow NewControlWindow = {
20, 20, /* start LeftEdge, TopEdge */
605, 172, /* start Width, Height */
2, 3, /* DetailPen, BlockPen */
GADGETUP | CLOSEWINDOW | MENUPICK, /* IDCMP FLAGS */
WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | ACTIVATE, /* Flags */
&StrGadget[4], /* Pointer to FirstGadget */
NULL, /* no pointer to first CheckMark */
"String Gadgets", /* Title (can be NULL) */
NULL, /* no Pointer to Screen */
NULL, /* no Pointer to BitMap */
20, 20, /* Min/max Sizable to (w/h) */
321, 123, /* These aint used, can't size */
WBENCHSCREEN /* Type of screen window appears in */
};
/*****************************************************************/
/* Menu declarations */
/*****************************************************************/
struct IntuiText ghost_text = {
2,1,JAM2, /* Frontpen, Backpen, Draw Mode */
5,1,NULL, /* Left and Top offsets, Font */
"GHOST",NULL } ; /* Text to display,next IntuiText */
struct MenuItem ghost_item = {
NULL,0,5,140,10, /* Next item, left,top,width,height */
HIGHCOMP | ITEMENABLED | ITEMTEXT | COMMSEQ,
NULL, (APTR) &ghost_text, /* MutualExclude, ItemFill (text) */
NULL, 'G', NULL } ; /* SelectFill, Command, Subitem */
struct IntuiText scrollup_text = {
2,1,JAM2, /* Frontpen, Backpen, Draw Mode */
5,1,NULL, /* Left and Top offsets, Font */
"SCROLL UP",NULL } ; /* Text to display,next IntuiText */
struct MenuItem scrollup_item = {
&ghost_item,0,15,140,10, /* Next item, left,top,width,height */
HIGHCOMP | ITEMENABLED | ITEMTEXT | COMMSEQ,
NULL, (APTR) &scrollup_text, /* MutualExclude, ItemFill (text) */
NULL, 'U', NULL } ; /* SelectFill, Command, Subitem */
struct IntuiText scrolldn_text = {
2,1,JAM2, /* Frontpen, Backpen, Draw Mode */
5,1,NULL, /* Left and Top offsets, Font */
"SCROLL DOWN",NULL } ; /* Text to display,next IntuiText */
struct MenuItem scrolldn_item = {
&scrollup_item,0,25,140,10, /* Next item, left,top,width,height */
HIGHCOMP | ITEMENABLED | ITEMTEXT | COMMSEQ,
NULL, (APTR) &scrolldn_text, /* MutualExclude, ItemFill (text) */
NULL, 'D', NULL } ; /* SelectFill, Command, Subitem */
struct Menu gadget_menu = {
NULL, 0, 0, 60, 10, /* Next menu, left,top,width,height */
MENUENABLED, "Gadget", /* Flags, text */
&scrolldn_item } ; /* Pointer to first menu item */
/****************************************************************/
/* Main program */
/****************************************************************/
main()
{
struct MenuItem *ItemAddress();
ULONG Signals, MIClass, MICode, itemnum;
APTR MIAddress;
int i,k=0, gad_pos, real_pos;
if (!(IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library", LIBRARY_VERSION)))
{
printf("Can't open the intuition library\n");
MyCleanup();
exit(FALSE);
}
if (!(GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library", LIBRARY_VERSION)))
{
printf("Can't open the graphics library\n");
MyCleanup();
exit(FALSE);
}
if (!(ControlWindow = (struct Window *)OpenWindow(&NewControlWindow)))
{
printf("Couldn't open the control window.\n");
MyCleanup();
exit(FALSE);
}
SetMenuStrip(ControlWindow, &gadget_menu);
for (i=0; i<10; i++)
for (;;) { /* wait for a signal and process it */
Signals = Wait(1 << ControlWindow->UserPort->mp_SigBit);
if (Signals & (1<< ControlWindow->UserPort->mp_SigBit)) {
/* Process the Intuition message */
while (MyIntuiMessage=(struct IntuiMessage *)
GetMsg(ControlWindow->UserPort))
{
/* Get all the needed info and reply to message */
MIClass = MyIntuiMessage->Class;
MICode = MyIntuiMessage->Code;
MIAddress = MyIntuiMessage->IAddress;
ReplyMsg(MyIntuiMessage);
/* Determine what the message was for */
switch (MIClass) {
case MENUPICK:
while (MICode != MENUNULL)
{
itemnum = ITEMNUM(MICode);
switch(itemnum)
{
/* User chose ghost */
case 2:
/* Remove the gadget from Intuition's control */
/* before we change any values. */
gad_pos = RemoveGList(ControlWindow,&StrGadget[4],1);
/* Do a bitwise exclusive OR to toggle the flag. */
/* I do not use the functions OnGadget and OffGadget */
/* (which would produce the same effect), because */
/* they call RefreshGadgets. This routine refreshes */
/* ALL gadgets from that gadget on, and can cause */
/* a noticable flicker depending upon where the */
/* gadget is located in the list. */
StrGadget[4].Flags ^= GADGDISABLED;
/* Return the gadget to Intuition's control. */
real_pos = AddGList(ControlWindow, &StrGadget[4],
gad_pos, 1, NULL);
/* Refresh the display of the gadget. */
RefreshGList(&StrGadget[4], ControlWindow, NULL,1);
break;
/* User chose scroll up */
case 1:
if (k==9) k = 0; else k++;
/* Remove the gadgets from Intuition's control */
/* before we change any values. */
gad_pos = RemoveGList(ControlWindow, &StrGadget[4], 5);
for (i=0; i<5; i++)
{
StringInfo[i].Buffer = item_string[(i+k)%10];
StringInfo[i].BufferPos = 0;
StringInfo[i].NumChars = 0;
}
/* Return the gadgets to Intuition's control. */
real_pos = AddGList(ControlWindow, &StrGadget[4],
gad_pos, 5, NULL);
/* Refresh the display of the gadgets. */
RefreshGList(&StrGadget[4], ControlWindow, NULL,5);
break;
/* User chose scroll down */
case 0:
if (k==0) k = 9; else k--;
/* Remove the gadgets from Intuition's control */
/* before we change any values. */
gad_pos = RemoveGList(ControlWindow, &StrGadget[4], 5);
for (i=0; i<5; i++)
{
StringInfo[i].Buffer = item_string[(i+k)%10];
StringInfo[i].BufferPos = 0;
StringInfo[i].NumChars = 0;
}
/* Return the gadgets to Intuition's control. */
real_pos = AddGList(ControlWindow, &StrGadget[4],
gad_pos, 5, NULL);
/* Refresh the display of the gadgets. */
RefreshGList(&StrGadget[4], ControlWindow, NULL,5);
break;
} /* switch */
MICode = (ItemAddress(&gadget_menu,MICode))->NextSelect;
} /* while */
break;
case CLOSEWINDOW: /* bye! */
/* reply to any outstanding messages */
while (MyIntuiMessage = (struct IntuiMessage *) GetMsg(
ControlWindow->UserPort))
ReplyMsg(MyIntuiMessage);
MyCleanup();
exit(TRUE);
break;
default:
printf("Unhandled Message Received.\n");
break;
} /* switch */
} /* while */
} /* if */
} /* for */
} /* main */
MyCleanup()
{
if (ControlWindow) CloseWindow(ControlWindow);
if (GfxBase) CloseLibrary(GfxBase);
if (IntuitionBase) CloseLibrary(IntuitionBase);
}